package com.ricchieri.datamodel;

import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import com.ricchieri.model.UserPhone;

public class UserPhoneDataModel extends ListDataModel<UserPhone> implements SelectableDataModel<UserPhone> {  

    public UserPhoneDataModel() {
    }

    public UserPhoneDataModel(List<UserPhone> data) {
        super(data);
    }
    
    @Override
    public UserPhone getRowData(String rowKey) {

        @SuppressWarnings("unchecked")
		List<UserPhone> users = (List<UserPhone>) getWrappedData();
        
        for(UserPhone user : users) {
            if(user.getPhoneType().equals(rowKey))
                return user;
        }
        
        return null;
    }

    @Override
    public Object getRowKey(UserPhone user) {
        return user.getPhoneType();
    }
}
                    